<?php
namespace app\business\controller;
use app\business\model\BusinessClassify;
use app\business\model\BusinessLogin;
use think\Controller;
use app\business\controller\Base;
use think\Db;
use think\Session;

class Cash extends Base
{
    public function index()
    {
        $username = Session::get('username');

        $count = BusinessLogin::where('username',$username)->find();

        $num=$count['business_id'];

        $data = Db::table('business_cash')->where('business_id',$num)->find();

        $this->assign('data',$data);

        return $this->fetch();
    }

    public function store()
    {
        $username = Session::get('username');

        $count = BusinessLogin::where('username',$username)->find();

        $num=$count['business_id'];

        $time = time();

        $data = [
            'cash_type' => $_POST['cash_type'],
            'cash_name' => $_POST['cash_name'],
            'cash_num'  => $_POST['cash_user'],
            'back_name' => $_POST['back_name'],
            'cash_money' => $_POST['cash_num'],
            'business_id'   => $num,
            'create_time' => $time
        ];
        Db::table('business_cash_get')->insert($data);
        $info = Db::table('business_cash')->where('business_id',$num)->find();
        $money = $info['cash_num']-$data['cash_money'];
        Db::table('business_cash')->where('business_id',$num)->update(['cash_num'=>$money]);
        return $this->redirect('index');
    }
}